package com.bw.wxy.mvp.model.entity;

import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;

import java.util.ArrayList;
import java.util.List;

public class TextBannerEntity extends BaseEntity{

    public String values;

    public List<Values> getValues(){
        if (values.isEmpty())
            return null;
        List<Values> list = new ArrayList<>();
        //new Gson().fromJson(values,Values.class)
        //[{}.{}]
        try {
            JSONArray jsonArray = new JSONArray(values);
            for (int i = 0;i < jsonArray.length();i ++){
                String item = jsonArray.getString(i);
                Values entity = new Gson().fromJson(item,Values.class);
                list.add(entity);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        //为测试效果将list中数据进行复用
        for (int i = 1;i < 5;i ++){
            Values entity = list.get(0);
            list.add(entity);
        }
        return list;
    }

    public static class Values{
        public int news_type;
        public String news_author;
        public String news_value;
        public String news_title;
        public String news_url;
        public long news_time;
        public long author_id;
        public long channel_id;
        public long news_id;
    }

//    /**
//     * values : [{"medias":null,"news_type":0,"news_author":"string","news_value":"string","news_title":"string","news_url":"string","news_time":0,"author_id":0,"channel_id":0,"news_id":37},{"medias":null,"news_type":0,"news_author":"编辑1","news_value":"测试新闻1","news_title":"测试1","news_url":"http://118.195.161.134:8066/index.html#/","news_time":1622029278,"author_id":1,"channel_id":1,"news_id":38},{"medias":null,"news_type":0,"news_author":"编辑1","news_value":"测试新闻2","news_title":"测试2","news_url":"http://118.195.161.134:8066/index.html#/","news_time":1622029278,"author_id":1,"channel_id":1,"news_id":39},{"medias":null,"news_type":0,"news_author":"编辑1","news_value":"测试新闻3","news_title":"测试3","news_url":"http://118.195.161.134:8066/index.html#/","news_time":1622029278,"author_id":1,"channel_id":1,"news_id":40},{"medias":null,"news_type":0,"news_author":"编辑1","news_value":"测试新闻4","news_title":"测试4","news_url":"http://118.195.161.134:8066/index.html#/","news_time":1622029278,"author_id":1,"channel_id":1,"news_id":41}]
//     */
//
//    private String values;
//
//    public String getValues() {
//        return values;
//    }
//
//    public void setValues(String values) {
//        this.values = values;
//    }
}

